package com.edu.exam.enums;

/**
 * 题目附件内容类型枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum QuestionAttachmentContentType {
    QUESTION("QUESTION", "题目图片"),
    OPTION("OPTION", "选项图片"),
    ANSWER("ANSWER", "答案图片"),
    EXPLANATION("EXPLANATION", "解析图片"),
    REFERENCE("REFERENCE", "参考资料"),
    SUPPLEMENT("SUPPLEMENT", "补充材料");

    private final String code;
    private final String description;

    QuestionAttachmentContentType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码查找枚举值
     *
     * @param code 枚举代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static QuestionAttachmentContentType fromCode(String code) {
        for (QuestionAttachmentContentType type : QuestionAttachmentContentType.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("未知的题目附件内容类型代码: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 枚举描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static QuestionAttachmentContentType fromDescription(String description) {
        for (QuestionAttachmentContentType type : QuestionAttachmentContentType.values()) {
            if (type.description.equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("未知的题目附件内容类型描述: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}